<template>
  <div class="center">
    <el-row :gutter="20">
      <el-col :span="24"><div class="centerTitle">危机处理方案</div></el-col>
    </el-row>
    <el-form ref="form" :model="form" label-position="top">
      <el-form-item label="危机类型：">
        <el-col :span="12" :xl="{span: 24}">
          <el-select v-model="form.q1" placeholder="请选择危机类型">
            <el-option v-for="item in this.optionsList.crisis_list" :key="item.id" :label="item.title" :value="item.id"></el-option>
          </el-select>
        </el-col>
      </el-form-item>
      <el-form-item label="是否已经发生事件？">
        <el-radio-group v-model="form.q2" @change="againFn()">
          <el-radio label="1">没有发生</el-radio>
          <el-radio label="2">正在发生</el-radio>
          <el-radio label="3">已经发生</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="this.form.q2 === '3'" label="到目前为止，危机事件已经发生多长时间？">
        <el-radio-group v-model="form.q3">
          <el-radio label="1">一周内</el-radio>
          <el-radio label="2">超过一周</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="this.form.q2 === '2'" label="当事人是否失踪或死亡？">
        <el-radio-group v-model="form.q4">
          <el-radio label="1">是</el-radio>
          <el-radio label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="this.form.q4 !== '' && this.form.q3 === ''" label="发生地点？">
        <el-radio-group v-model="form.q5">
          <el-radio label="1">校内</el-radio>
          <el-radio label="2">校外</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="this.form.q2 !== '' && this.form.q4 !== '1'" label="当事人是否需要休学或休假？">
        <el-radio-group v-model="form.q6">
          <el-radio label="1">是</el-radio>
          <el-radio label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="this.form.q2 && this.form.q2 !== '1'" label="危机事件影响范围：">
        <el-col :span="12" :xl="{span: 24}">
          <el-select v-model="form.q7" placeholder="请选择危机事件影响范围">
            <el-option v-for="item in this.optionsList.influence_scope_list" :key="item.id" :label="item.title" :value="item.id"></el-option>
          </el-select>
        </el-col>
      </el-form-item>
      <el-form-item v-if="this.form.q2 && this.form.q2 !== '1'" label="危机事情现场情况">
        <el-radio-group v-model="form.q8">
          <el-radio label="1">现场有涉事人</el-radio>
          <el-radio label="2">现场没有涉事人</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item class="inputBox">
        <el-button type="primary" @click="submitFn()">查看方案</el-button>
      </el-form-item>
    </el-form>
    <plan-view v-if="this.isPlan" :isPlan="this.isPlan" :list="this.list" @noPlan="noPlan"></plan-view>
  </div>
</template>
<script>
import planView from './plan.vue'
import {APICRISISGETSUNDRY, APICRISISGETTREATMENTPLAN} from '@/common/api.js'
export default {
  components: {planView},
  data () {
    return {
      optionsList: {},
      form: {
        q1: '',
        q2: '',
        q3: '',
        q4: '',
        q5: '',
        q6: '',
        q7: '',
        q8: ''
      },
      isPlan: false,
      list: []
    }
  },
  created () {
    this.selectFn()
  },
  methods: {
    goBack () {
      this.$router.push({path: '/crisis'})
    },
    selectFn () {
      APICRISISGETSUNDRY().then((res) => {
        this.optionsList = res.data
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    againFn () {
      this.form.q3 = ''
      this.form.q4 = ''
      this.form.q5 = ''
      this.form.q6 = ''
      this.form.q7 = ''
      this.form.q8 = ''
    },
    submitFn () {
      APICRISISGETTREATMENTPLAN(this.form).then((res) => {
        this.list = res.data
        this.planFn()
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    planFn () { // 状态管理
      this.isPlan = true
    },
    noPlan (type) {
      this.isPlan = false
    }
  }
}
</script>
<style>
  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
</style>
